# coding=utf-8
import os
import allure
import pytest,jsonpath
from common.assert_operator import Pact,string_assert
from common.logger import Logger
from common.read_yaml import ReadYaml_By_Root_Dict, ReadYaml
from common.verification import Verification

string_assert = string_assert() # 字符串校验类
pact = Pact() # 契约校验类
verification = Verification()
data = ReadYaml().get_yaml_data(f'{os.path.abspath(__file__).split("_test.py")[0]}.yml')   # 读取数据

@allure.feature('聚合表决')  # 测试报告显示测试功能
class Test_02_6_FinishNode_AggregateVote():

    # 获取yml文件中[聚合表决]的数据参数
    approve_process_params = data['聚合表决结束']
    # 获取yml的title，并作为ids的值传给用例
    ids_list = jsonpath.jsonpath(approve_process_params,"$[*][0]")
    @pytest.mark.parametrize("title, param, expect", approve_process_params,ids=ids_list)
    def test_FinishNode_Approve_After_AddSign(self, user_login, title, param, expect):
        allure.dynamic.description(f"{param['description']}")  # # 动态解析用例描述在测试报告中展示
        user,process_name = param['user'],param['process_name']
        DBNodeVerify, MessageVerify = '主节点校验', '消息校验'
        contract_format = pact.approve_pact_format()    # 审批响应契约格式
        main = user_login.goto_Approve_Process(user)    # 登录到审批类实例
        process_instance_resp = main.open_process_instance(process_name)   # 通过流程名称打开流程实例
        response = main.approve_submit(param, process_instance_resp)    # 提交审批
        string_assert.eq(response.status_code, 200)
        verification.after_end(process_name,response,expect,contract_format,DBNodeVerify,MessageVerify)    # 审批结束后校验
        Logger.info("*************** {}结束执行用例 ***************".format(title))
